package main

import (
	"github.com/gin-gonic/gin"
	"time"
	"fmt"
)

// 中间件应用

func myTime(c *gin.Context) {
	start := time.Now()
	c.Next()
	// 统计时间
	since := time.Since(start)
	fmt.Println("程序用时:",since)
}

func main(){
	r := gin.Default()
	r.Use(myTime)
	shoppingGroup := r.Group("/shopping")
	{
		shoppingGroup.GET("/index", shopIndexHandler)
		shoppingGroup.GET("/home", shopHomeHandler)
	}

	r.Run(":8004")
}

func shopIndexHandler(c *gin.Context){
	time.Sleep( 5 * time.Second)
}

func shopHomeHandler(c *gin.Context){
	time.Sleep(2 * time.Second)
}